﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using Framework.Library.Base.Base;
using Framework.Library.Base.Extensions;
using Framework.Library.Data.DAL;
using Framework.Library.Data.DAO;
using System.Linq;
using Framework.Library.Core.Utils.Images;
using Framework.Library.Core.Utils;
using Framework.Library.Core.Config;
using Framework.Library.Data.DAL.JObject;

namespace Framework.Portal.Layouts.Client.Modules.Menu
{
    public partial class Yeuthich : BaseControl
    {
        private static List<PortalMenu> lst = new List<PortalMenu>();

        public Yeuthich()
        {
        }

        public Yeuthich(JSection section)
        {
            if(!string.IsNullOrEmpty(section.parameter))
            {
                string[] arrParams = section.parameter.Split('&');
                if (arrParams.Length > 0)
                    menuId = Convert.ToInt32(arrParams[0].Split('=')[1]);
                if (arrParams.Length > 1)
                    catId = Convert.ToInt32(arrParams[1].Split('=')[1]);
            }
            MENUNAME = section.title;
        }
        public string MENUNAME = string.Empty;

        protected static int catId = 0;
        protected static int menuId = 0;
        protected static int curMenu = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int totalRecord;
                List<TeenioContent> lstContent = ManagerFactory.TeenioContentManager.GetList(catId, 3, 2, 0, TeenioContentOrder.VIEW, 0, 3, out totalRecord);
                if (lstContent != null)
                {
                    rptContent.DataSource = lstContent;
                    rptContent.DataBind();
                }
            }
        }

        protected void rptContent_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var info = (TeenioContent)e.Item.DataItem;
                var imgAvatar = (Image)e.Item.FindControl("imgAvatar");
                var hplTitle = (HyperLink)e.Item.FindControl("hplTitle");
                var hplAuthor = (HyperLink)e.Item.FindControl("hplAuthor");

                if (!string.IsNullOrEmpty(info.CONTENT_AVATAR))
                    imgAvatar.ImageUrl = ImagesUtils.GetImage(info.CONTENT_AVATAR, 77, 62);
                hplTitle.Text = ConvertUtility.ToSubString(info.CONTENT_HEADLINE, 40);
                hplTitle.NavigateUrl = cfg.ArticlePath(info.CONTENT_PORTALID, info.MENUID, info.CONTENT_ID);
                hplAuthor.NavigateUrl = "http://my.go.vn/?id=" + info.CONTENT_CREATEUSERID;
                hplAuthor.Text = info.CONTENT_CREATEUSERNAME;
            }
        }
    }
}